/*****************************************************************************************
   
   Copyright (c) Microsoft Corporation. All rights reserved.

   Use of this code sample is subject to the terms of the Microsoft
   Permissive License, a copy of which should always be distributed with
   this file.  You can also access a copy of this license agreement at:
   http://www.microsoft.com/resources/sharedsource/licensingbasics/permissivelicense.mspx

 ****************************************************************************************/

using System;

namespace GrooveCommands
{
	class GrooveReadEvents : CommandUtils.GrooveUtilBase
	{
		private string m_CallbackURI;
		
		private long m_Sequence;

		private bool m_IncludeSources;
		private bool m_DeleteEvents;
		private bool m_SummaryOnly;

		[STAThread]
		static void Main(string[] i_Arguments)
		{
			CommandUtils.UtilAppMain.RunApplication(new GrooveReadEvents(i_Arguments));
		}

		public GrooveReadEvents(string[] i_Arguments)
			: base (i_Arguments)
		{
			base.UsageMessage = "GrooveReadEvents [PARAMS...]";
			base.HelpMessage = 
				"GrooveReadEvents\r\n\t" + 
				"Reads event queue summary information\r\n" +
				"Parameters:\r\n\t" +
				"/CallbackURI=        The Web Services URI of the event queue\r\n\t" +
				"[/Sequence=          The sequence # to read up to (default=0=all)]\r\n\t" +
				"[/IncludeSources     Specifies inclusion of event sources]\r\n\t" +
				"[/DeleteEvents       Specifies deletion of events after reading]\r\n\t" +
				"[/SummaryOnly        Specifies to show summary info only]\r\n\t" +
				"[/Account=           The Web Services URI for the Groove account]\r\n\t" +
				"[/Identity=          The Web Services URI for the Groove identity]\r\n\t" +
				"[/RequestKey=        Token used to communicate Groove host]\r\n\t" +
				"[/Host=              The remote Groove host name to issue commands to]\r\n\t" +
				"[/Port=              The remote Groove host port to issue commands to]\r\n\t" +
				"[/Timeout=           Timeout (in ms) for Web Services method execution]\r\n\t" +
				"[/X=                 Configuration file to use for parameter input]\r\n\t" +
				"\r\n";
		}

		public override CheckResult CheckParameters()
		{
			CommandUtils.UtilBase.CheckResult CheckResult = base.CheckParameters();
			if (CheckResult != CommandUtils.UtilBase.CheckResult.Succeeded )
				return CheckResult;
		
			m_CallbackURI = base.GetParameterValue("CallbackURI");
			if (System.String.IsNullOrEmpty(m_CallbackURI))
			{
				base.DisplayUsage("You must specify a callback uri.");
				return CommandUtils.UtilBase.CheckResult.Failed;
			}

			m_IncludeSources = base.GetParameterValueFlag("IncludeSources");

			m_DeleteEvents = base.GetParameterValueFlag("DeleteEvents");

			m_Sequence = base.GetParameterValueInt("Sequence", 0);

			m_SummaryOnly = base.GetParameterValueFlag("SummaryOnly");

			return base.CheckUnusedParameters();
		}

		public override CommandUtils.UtilBase.CheckResult Run()
		{
			GrooveWebServicesV12Helpers.Event NewEvent = new GrooveWebServicesV12Helpers.Event
				(
				base.Identity.Context,
				base.IdentityURI,
				m_CallbackURI
				);

			GrooveWebServicesV12Helpers.GrooveEventsWebService.ExtendedEventData ExtendedEventData = NewEvent.ReadExtended
				(
				m_Sequence,
				m_IncludeSources,
				m_DeleteEvents
				);

			base.StandardOutput.WriteLine("<ExtendedEventData>");

			string Output = System.String.Format
				(
				"   <EventQueueSummary CallbackURI='{0}' Count='{1}' LastModifiedTime='{2}' Sequence='{3}'>",
				m_CallbackURI,
				ExtendedEventData.EventQueueSummary.Count,
				ExtendedEventData.EventQueueSummary.LastModifiedTime,
				ExtendedEventData.EventQueueSummary.Sequence
				);

			base.StandardOutput.WriteLine(Output);
			
			if (m_IncludeSources)
			{
				foreach (string EventSource in ExtendedEventData.EventQueueSummary.EventSources)
					base.StandardOutput.WriteLine("      <EventSource URI='" + EventSource + "'/>");
			}

			base.StandardOutput.WriteLine("   </EventQueueSummary>");

			if (!m_SummaryOnly && (ExtendedEventData.EventList != null))
			{
				foreach (GrooveWebServicesV12Helpers.GrooveEventsWebService.Event Event in ExtendedEventData.EventList)
				{
					string EventInfo = System.String.Format
						(
						"   <Event Class='{0}' SubscriptionID='{1}' EventSource='{2}' EventType='{3}'>",
						Event.EventClass,
						Event.SubscriptionID,
						Event.EventSource,
						Event.EventType
						);

					base.StandardOutput.WriteLine(EventInfo);

					this.WriteEventData(Event.EventData);

					base.StandardOutput.WriteLine("   </Event>");
				}
			}

			base.StandardOutput.WriteLine("</ExtendedEventData>");

			return CommandUtils.UtilBase.CheckResult.Succeeded;
		}

		private void WriteEventData(GrooveWebServicesV12Helpers.GrooveEventsWebService.EventData i_EventData)
		{
			#region FormsEventData

			bool IsFormsEventData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordAddEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordDeleteEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordUpdateEventData);

			if (IsFormsEventData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordDeleteEventData GrooveFormsRecordDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data><Records>");
					
					foreach (string RecordID in GrooveFormsRecordDeleteEventData.RecordIDs)
						base.StandardOutput.WriteLine("         <Record ID='" + RecordID + "'/>");
						
					base.StandardOutput.WriteLine("      </Records></Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveFormsWebService.FormsRecordDataSet FormsRecordDataSet = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordAddEventData)
						FormsRecordDataSet = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordAddEventData)i_EventData).RecordDataSet;
					else
						FormsRecordDataSet = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFormsRecordUpdateEventData)i_EventData).RecordDataSet;

					GrooveWebServicesV12Helpers.Forms.RecordDataSet RecordDataSet = new GrooveWebServicesV12Helpers.Forms.RecordDataSet(FormsRecordDataSet);
					System.Data.DataSet DataSet = RecordDataSet.ToDataSet();
					base.StandardOutput.WriteLine(DataSet.GetXml());
				}

				return;
			}

			#endregion

            #region Forms2EventData

            bool IsForms2EventData =
                (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordAddEventData) ||
                (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordDeleteEventData) ||
                (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordUpdateEventData);

            if (IsForms2EventData)
            {
                if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordDeleteEventData)
                {
                    GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordDeleteEventData GrooveFormsRecordDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordDeleteEventData)i_EventData;

                    base.StandardOutput.WriteLine("      <Data><Records>");

                    foreach (string RecordID in GrooveFormsRecordDeleteEventData.RecordIDs)
                        base.StandardOutput.WriteLine("         <Record ID='" + RecordID + "'/>");

                    base.StandardOutput.WriteLine("      </Records></Data>");
                }
                else
                {
                    GrooveWebServicesV12Helpers.GrooveForms2WebService.Forms2RecordDataSet FormsRecordDataSet = null;

                    if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordAddEventData)
                        FormsRecordDataSet = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordAddEventData)i_EventData).RecordDataSet;
                    else
                        FormsRecordDataSet = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveForms2RecordUpdateEventData)i_EventData).RecordDataSet;

                    GrooveWebServicesV12Helpers.Forms2.RecordDataSet RecordDataSet = new GrooveWebServicesV12Helpers.Forms2.RecordDataSet(FormsRecordDataSet);
                    System.Data.DataSet DataSet = RecordDataSet.ToDataSet();
                    base.StandardOutput.WriteLine(DataSet.GetXml());
                }

                return;
            }

            #endregion

			#region CalendarEventData

			bool IsCalendarData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarAddEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarDeleteEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarUpdateEventData);

			if (IsCalendarData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarDeleteEventData GrooveCalendarDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data>");
				
					foreach (string CalendarID in GrooveCalendarDeleteEventData.CalendarIDs)
						base.StandardOutput.WriteLine("         <CalendarData ID='" + CalendarID + "'/>");
					
					base.StandardOutput.WriteLine("      </Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveCalendarWebService.CalendarEntry[] CalendarEntries = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarAddEventData)
						CalendarEntries = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarAddEventData)i_EventData).CalendarEntries;
					else
						CalendarEntries = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveCalendarUpdateEventData)i_EventData).CalendarEntries;

					System.Data.DataSet DataSet = GrooveWebServicesV12Helpers.Calendar.CalendarTool.CreateDataSetFromCalendarEntries(CalendarEntries);
					base.StandardOutput.WriteLine(DataSet.GetXml());
				}

				return;
			}

			#endregion

			#region DiscussionEventData

			bool IsDiscussionData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionAddEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionDeleteEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionUpdateEventData);

			if (IsDiscussionData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionDeleteEventData GrooveDiscussionDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data>");
				
					foreach (string DiscussionID in GrooveDiscussionDeleteEventData.DiscussionIDs)
						base.StandardOutput.WriteLine("         <DiscussionData ID='" + DiscussionID + "'/>");
					
					base.StandardOutput.WriteLine("      </Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveDiscussionWebService.DiscussionEntry[] DiscussionEntries = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionAddEventData)
						DiscussionEntries = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionAddEventData)i_EventData).DiscussionEntries;
					else
						DiscussionEntries = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveDiscussionUpdateEventData)i_EventData).DiscussionEntries;

					System.Data.DataSet DataSet = GrooveWebServicesV12Helpers.Discussion.DiscussionTool.CreateDataSetFromDiscussionEntries(DiscussionEntries);
					base.StandardOutput.WriteLine(DataSet.GetXml());
				}

				return;
			}

			#endregion

			#region FilesEventData

			bool IsFilesData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileAddEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileDeleteEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileUpdateEventData);

			if (IsFilesData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileDeleteEventData GrooveFileDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data>");
				
					base.StandardOutput.WriteLine("         <FileData ID='" + GrooveFileDeleteEventData.FileID + "'/>");
					
					base.StandardOutput.WriteLine("      </Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveFilesWebService.FileDescriptor FileDescriptor = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileAddEventData)
						FileDescriptor = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileAddEventData)i_EventData).FileDescriptor;
					else
						FileDescriptor = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveFileUpdateEventData)i_EventData).FileDescriptor;

					base.StandardOutput.WriteLine("      <Data>");
				
					string FileData = System.String.Format
						(
						"         <FileData ID='{0}' URI='{1}' CreatedBy='{2}' ModifiedBy='{3}' Created='{4}' Modified='{5}' FolderID='{6}' Unread='{7}' Name='{8}' DisplayName='{9}' Type='{10}' Size='{11}' LaunchURL='{12}' DownloadState='{13}' AutoDownload='{14}' DownloadSizeLimit='{15}' Count='{16}' />",
						FileDescriptor.ID,
						FileDescriptor.URI,
						CommandUtils.UtilStatic.XMLEncode(FileDescriptor.CreatedBy),
						CommandUtils.UtilStatic.XMLEncode(FileDescriptor.ModifiedBy),
						FileDescriptor.Created,
						FileDescriptor.Modified,
						FileDescriptor.FolderID,
						FileDescriptor.Unread,
						CommandUtils.UtilStatic.XMLEncode(FileDescriptor.Name),
						CommandUtils.UtilStatic.XMLEncode(FileDescriptor.DisplayName),
						FileDescriptor.Type,
						FileDescriptor.Size,
						FileDescriptor.LaunchURL,
						FileDescriptor.DownloadState,
						FileDescriptor.AutoDownload,
						FileDescriptor.DownloadSizeLimit,
						FileDescriptor.Count
						);

					base.StandardOutput.WriteLine(FileData);
					
					base.StandardOutput.WriteLine("      </Data>");
				}

				return;
			}

			#endregion

			#region ContactEventData

			bool IsContactData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactAddEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactDeleteEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactUpdateEventData);

			if (IsContactData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactDeleteEventData GrooveContactDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data>");
			
					base.StandardOutput.WriteLine("         <ContactData URI='" + GrooveContactDeleteEventData.ContactURI + "'/>");
					
					base.StandardOutput.WriteLine("      </Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveContactsWebService.Contact Contact = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactAddEventData)
						Contact = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactAddEventData)i_EventData).Contact;
					else
						Contact = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveContactUpdateEventData)i_EventData).Contact;

					base.StandardOutput.WriteLine("      <Data>");
				
					string ContactData = System.String.Format
						(
						"         <ContactData URI='{0}' Name='{1}' Awareness='{2}' TimeWentIdle='{3}' VCardURI='{4}' Type='{5}'  />",
						Contact.URI,
						CommandUtils.UtilStatic.XMLEncode(Contact.Name),
						Contact.Awareness,
						Contact.TimeWentIdle,
						Contact.VCard,
						Contact.Type
						);

					base.StandardOutput.WriteLine(ContactData);
					
					base.StandardOutput.WriteLine("      </Data>");
				}

				return;
			}

			#endregion

			#region MemberEventData

			bool IsMemberData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberAddEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberDeleteEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberUpdateEventData);

			if (IsMemberData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberDeleteEventData GrooveMemberDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data>");
			
					base.StandardOutput.WriteLine("         <MemberData MemberURI='" + GrooveMemberDeleteEventData.MemberURI + "' SpaceURI='" + GrooveMemberDeleteEventData.SpaceURI + "'/>");
					
					base.StandardOutput.WriteLine("      </Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveMembersWebService.Member Member = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberAddEventData)
						Member = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberAddEventData)i_EventData).Member;
					else
						Member = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberUpdateEventData)i_EventData).Member;

					base.StandardOutput.WriteLine("      <Data>");

					string ActiveInTools = "";
					foreach (string ActiveInTool in Member.ActiveInTool)
					{
						if (System.String.IsNullOrEmpty(ActiveInTools))
							ActiveInTools = ActiveInTool;
						else
							ActiveInTools += ", " + ActiveInTool;
					}

					string MemberData = System.String.Format
						(
						"         <MemberData URI='{0}' ContactURI='{1}' Name='{2}' Role='{3}' Awareness='{4}' AwarenessState='{5}' TimeWentIdle='{6}' SyncState='{7}' ActiveInSpace='{8}' ActiveInToolURIs='{9}' />",
						Member.URI,
						Member.Contact,
						CommandUtils.UtilStatic.XMLEncode(Member.Name),
						Member.Role,
						Member.Awareness,
						Member.AwarenessState,
						Member.TimeWentIdle,
						Member.SyncState,
						Member.ActiveInSpace,
						ActiveInTools
						);

					base.StandardOutput.WriteLine(MemberData);
					
					base.StandardOutput.WriteLine("      </Data>");
				}

				return;
			}

			#endregion

			#region MemberAwarenessEventData

			bool IsMemberAwarenessData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberAwarenessEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberEnterSpaceEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberExitSpaceEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberEnterToolEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberExitToolEventData);

			if (IsMemberAwarenessData)
			{
				GrooveWebServicesV12Helpers.GrooveMembersWebService.Member Member = null;

				string ExtendedAttribute = "";

				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberAwarenessEventData)
				{
					Member = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberAwarenessEventData)i_EventData).Member;
				}
				else if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberEnterSpaceEventData)
				{
					Member = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberEnterSpaceEventData)i_EventData).Member;
					ExtendedAttribute = "SpaceURI='" + ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberEnterSpaceEventData)i_EventData).SpaceURI + "'";
				}
				else if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberExitSpaceEventData)
				{
					Member = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberExitSpaceEventData)i_EventData).Member;
					ExtendedAttribute = "SpaceURI='" + ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberExitSpaceEventData)i_EventData).SpaceURI + "'";
				}
				else if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberEnterToolEventData)
				{
					Member = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberEnterToolEventData)i_EventData).Member;
					ExtendedAttribute = "SpaceURI='" + ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberEnterToolEventData)i_EventData).ToolURI + "'";
				}
				else
				{
					Member = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberExitToolEventData)i_EventData).Member;
					ExtendedAttribute = "SpaceURI='" + ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMemberExitToolEventData)i_EventData).ToolURI + "'";
				}

				base.StandardOutput.WriteLine("      <Data>");

				string ActiveInTools = "";
				foreach (string ActiveInTool in Member.ActiveInTool)
				{
					if (System.String.IsNullOrEmpty(ActiveInTools))
						ActiveInTools = ActiveInTool;
					else
						ActiveInTools += ", " + ActiveInTool;
				}

				string MemberAwarenessData = System.String.Format
					(
					"         <MemberAwarenessData URI='{0}' ContactURI='{1}' Name='{2}' Role='{3}' Awareness='{4}' AwarenessState='{5}' TimeWentIdle='{6}' SyncState='{7}' ActiveInSpace='{8}' ActiveInToolURIs='{9}' {10}/>",
					Member.URI,
					Member.Contact,
					CommandUtils.UtilStatic.XMLEncode(Member.Name),
					Member.Role,
					Member.Awareness,
					Member.AwarenessState,
					Member.TimeWentIdle,
					Member.SyncState,
					Member.ActiveInSpace,
					ActiveInTools,
					ExtendedAttribute
					);

				base.StandardOutput.WriteLine(MemberAwarenessData);
					
				base.StandardOutput.WriteLine("      </Data>");
			}

			#endregion

			#region MessageEventData

			bool IsMessageData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageReceivedEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageOpenedEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageSentEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageDeleteEventData);

			if (IsMessageData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageDeleteEventData GrooveMessageDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data>");
			
					base.StandardOutput.WriteLine("         <MessageData URI='" + GrooveMessageDeleteEventData.MessageURI + "'/>");
					
					base.StandardOutput.WriteLine("      </Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveMessagesWebService.MessageHeader MessageHeader = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageReceivedEventData)
						MessageHeader = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageReceivedEventData)i_EventData).MessageHeader;
					else if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageOpenedEventData)
						MessageHeader = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageOpenedEventData)i_EventData).MessageHeader;
					else
						MessageHeader = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveMessageSentEventData)i_EventData).MessageHeader;

					base.StandardOutput.WriteLine("      <Data>");

					string MessageData = System.String.Format
						(
						"         <MessageData URI='{0}' ID='{1}' Category='{2}' HasVoiceMemo='{3}' HasAttachments='{4}'>",
						MessageHeader.URI,
						MessageHeader.ID,
						MessageHeader.Category,
						MessageHeader.HasVoiceMemo,
						MessageHeader.HasAttachments
						);

					base.StandardOutput.WriteLine(MessageData);

					string SenderData = System.String.Format
						(
						"            <Sender URI='{0}' Name='{1}'/>",
						MessageHeader.Sender.URI,
						CommandUtils.UtilStatic.XMLEncode(MessageHeader.Sender.Name)
						);

					base.StandardOutput.WriteLine(SenderData);

					foreach (GrooveWebServicesV12Helpers.GrooveMessagesWebService.MessageContact MessageContact in MessageHeader.Recipients)
					{
						string RecipientData = System.String.Format
							(
							"            <Recipient URI='{0}' Name='{1}'/>",
							MessageContact.URI,
							CommandUtils.UtilStatic.XMLEncode(MessageContact.Name)
							);

						base.StandardOutput.WriteLine(RecipientData);
					}

					base.StandardOutput.WriteLine("         </MessageData>");

					base.StandardOutput.WriteLine("      </Data>");
				}

				return;
			}

			#endregion

			#region SpaceEventData

			bool IsSpaceData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceAddEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceDeleteEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceRenameEventData);

			if (IsSpaceData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceDeleteEventData GrooveSpaceDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data>");
			
					base.StandardOutput.WriteLine("         <SpaceData URI='" + GrooveSpaceDeleteEventData.SpaceURI + "'/>");
					
					base.StandardOutput.WriteLine("      </Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveSpacesWebService.Space Space = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceAddEventData)
						Space = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceAddEventData)i_EventData).Space;
					else
						Space = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveSpaceRenameEventData)i_EventData).Space;

					base.StandardOutput.WriteLine("      <Data>");
				
					string Version = null;
					if (Space.Version != null)
					{
						Version = System.String.Format
							(
							"{0}, {1}, {2}, {3}",
							Space.Version.Major,
							Space.Version.Minor,
							Space.Version.Custom,
							Space.Version.Sequence
							);
					}

					string SpaceData = System.String.Format
						(
						"         <SpaceData URI='{0}' Name='{1}' Description='{2}' Created='{3}' Modified='{4}' Local='{5}' IdentityURI='{6}' ToolsURI='{7}' MembersURI='{8}' Unread='{9}' Type='{10}' LocalURI='{11}' Version='{12}' />",
						Space.URI,
						CommandUtils.UtilStatic.XMLEncode(Space.Name),
						CommandUtils.UtilStatic.XMLEncode(Space.Description),
						Space.Created,
						Space.Modified,
						Space.Local,
						Space.IdentityURL,
						Space.Tools,
						Space.Members,
						Space.Unread,
						Space.Type,
						Space.LocalURI,
						Version
						);

					base.StandardOutput.WriteLine(SpaceData);
					
					base.StandardOutput.WriteLine("      </Data>");
				}

				return;
			}

			#endregion

			#region ToolEventData

			bool IsToolData = 
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolAddEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolDeleteEventData) ||
				(i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolRenameEventData);

			if (IsToolData)
			{
				if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolDeleteEventData)
				{
					GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolDeleteEventData GrooveToolDeleteEventData = (GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolDeleteEventData)i_EventData;

					base.StandardOutput.WriteLine("      <Data>");
			
					base.StandardOutput.WriteLine("         <ToolData URI='" + GrooveToolDeleteEventData.ToolURI + "'/>");
					
					base.StandardOutput.WriteLine("      </Data>");
				}
				else
				{
					GrooveWebServicesV12Helpers.GrooveToolsWebService.Tool Tool = null;

					if (i_EventData is GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolAddEventData)
						Tool = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolAddEventData)i_EventData).Tool;
					else
						Tool = ((GrooveWebServicesV12Helpers.GrooveEventsWebService.GrooveToolRenameEventData)i_EventData).Tool;

					base.StandardOutput.WriteLine("      <Data>");
				
					string ToolData = System.String.Format
						(
						"         <ToolData ID='{0}' URI='{1}' Name='{2}' Unread='{3}' Category='{4}' Creator='{5}' Owner='{6}' Type='{7}' ComponentResourceURL='{8}' LocalURI='{9}' MembersURI='{10}' Data='{11}' />",
						Tool.ID,
						Tool.URI,
						CommandUtils.UtilStatic.XMLEncode(Tool.Name),
						Tool.Unread,
						Tool.Category,
						Tool.Creator,
						Tool.Owner,
						Tool.Type,
						CommandUtils.UtilStatic.XMLEncode(Tool.ComponentResourceURL),
						Tool.LocalURI,
						Tool.MembersURI,
						Tool.Data
						);

					base.StandardOutput.WriteLine(ToolData);
					
					base.StandardOutput.WriteLine("      </Data>");
				}

				return;
			}

			#endregion

			//  If we get here then we don't understand the event data
			base.StandardOutput.WriteLine("Unknown Event Data: " + i_EventData.GetType().ToString());
		}
	}
}
